Skip to content

Upgrade test fixtures to 2.x project layouts #1301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 20, 2015

Conversation

raymondfeng
Copy link
Member

/to @bajtos
/cc @ritch

See #386

@raymondfeng raymondfeng force-pushed the feature/disable-include-access-tokens branch from 5ce2eb6 to 7349a80 Compare April 14, 2015 22:35
"foreignKey": "userId",
"options": {
"disableInclude": true
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, this option is not covered by your new tests, because the tests are explicitly overriding this option in models.json. Please consider writing few more test to verify that a) the built-in user disables include of access tokens b) user submodels inherit this setting by default too.

@bajtos bajtos assigned raymondfeng and unassigned bajtos Apr 15, 2015
@bajtos
Copy link
Member

bajtos commented Apr 15, 2015

The model change is not covered by tests. Other than that, the patch LGTM.

@raymondfeng raymondfeng force-pushed the feature/disable-include-access-tokens branch 4 times, most recently from 9abcb08 to 68a2344 Compare April 17, 2015 18:39
@raymondfeng
Copy link
Member Author

@bajtos PTAL again. I had to convert the test apps into LB 2.x layout, which is a great side effect.

@raymondfeng raymondfeng assigned bajtos and unassigned raymondfeng Apr 17, 2015
@bajtos
Copy link
Member

bajtos commented Apr 20, 2015

I had to convert the test apps into LB 2.x layout, which is a great side effect.

For posterity, can you please explain why was this needed?

  • LB 2.x project layout does not use defaultForType option, please remove it from all datasources.json files

app.use(apiPath, loopback.rest());
app.use(loopback.static(path.join(__dirname, 'public')));
app.use(loopback.urlNotFound());
app.use(loopback.errorHandler());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any particular reason why you are not using middleware.json and middleware phases in this app?

Are your tests relying on cookieParser at all? And why do they need static files from the public directory?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I just copied them from the existing fixture. I can clean them up.

@bajtos
Copy link
Member

bajtos commented Apr 20, 2015

I had to convert the test apps into LB 2.x layout, which is a great side effect.

Actually I think this is a wrong thing to do. LoopBack tests should not depend on loopback-boot, they should setup the application via code only.

  • Loading an external app from fixtures makes tests difficult to understand, one has to scan many files to understand what's going on.
  • loopback-boot is an optional component providing opinionated convention for project layout. LoopBack must work without loopback-boot too, and thus the unit-tests should not depend on loopback-boot.

IIRC, the main reason why the existing LoopBack tests are depending on loopback-boot is to ensure that LoopBack 1.x apps can be upgraded to LoopBack 2.x + loopback-boot 1.x with no breaking changes.

I think this issue deserves some discussion and it will be best to decouple it from your work on "Set disableInclude for User->AccessToken relation". Is there any way how to finish your fix without upgrading loopback-boot?

@bajtos bajtos assigned raymondfeng and unassigned bajtos Apr 20, 2015
@raymondfeng
Copy link
Member Author

Actually I think this is a wrong thing to do. LoopBack tests should not depend on loopback-boot, they should setup the application via code only.
Loading an external app from fixtures makes tests difficult to understand, one has to scan many files to understand what's going on.
loopback-boot is an optional component providing opinionated convention for project layout. LoopBack must work without loopback-boot too, and thus the unit-tests should not depend on loopback-boot.
IIRC, the main reason why the existing LoopBack tests are depending on loopback-boot is to ensure that LoopBack 1.x apps can be upgraded to LoopBack 2.x + loopback-boot 1.x with no breaking changes.
I think this issue deserves some discussion and it will be best to decouple it from your work on "Set disableInclude for User->AccessToken relation". Is there any way how to finish your fix without upgrading loopback-boot?

The project already has dependency on loopback-boot before the PR. I simply upgrade the fixtures to 2.x layout.

Migrating from 1.x to 2.x is not a main concern any more. I think it's better to use 2.x layout as developers sometimes try to follow what we do. If you feel strongly about removing the test fixtures, we can discuss that as a separate issue.

With 1.x layout, there is no way to use the base class such as User for REST. The test is meant to cover our main stream - LB 2.x.

@raymondfeng raymondfeng force-pushed the feature/disable-include-access-tokens branch from 68a2344 to bb3f971 Compare April 20, 2015 15:51
@bajtos
Copy link
Member

bajtos commented Apr 20, 2015

The project already has dependency on loopback-boot before the PR. I simply upgrade the fixtures to 2.x layout.

Migrating from 1.x to 2.x is not a main concern any more. I think it's better to use 2.x layout as developers sometimes try to follow what we do. If you feel strongly about removing the test fixtures, we can discuss that as a separate issue.

With 1.x layout, there is no way to use the base class such as User for REST. The test is meant to cover our main stream - LB 2.x.

I dig up the commit that added the dependency on loopback-boot - see c896c78. It seems the change was made purely in order to support test fixtures booting the app via loopback.boot(), in which case I agree with you that it's ok to upgrade loopback-boot to 2.x.

However, I still believe that we should keep the number of fixtures as small as possible, create loopback apps inside the tests purely code-wise and keep these apps as small as possibly.

@raymondfeng raymondfeng force-pushed the feature/disable-include-access-tokens branch from bb3f971 to b6efccc Compare April 20, 2015 16:08
@raymondfeng raymondfeng changed the title Set disableInclude for User->AccessToken relation Upgrade test fixtures to 2.x project layouts Apr 20, 2015
@raymondfeng
Copy link
Member Author

I decoupled the LB 2.x upgrade from disableInclude User.accessTokens. This PR is for the upgrade.

// to the wrong app instance
defaultApp = loopback.User.app;
loopback.User.app = null;
User = loopback.User.extend('TestUser', {}, {http: {path: 'test-users'}});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any particular reason why your are not using HTTP path /users? That way you will not have to change URLs in all the test cases below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because the model in use is a sub-model of User. If we don't explicitly specify http.path, it will default to /testusers.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So why can't you specify http.path: 'users', or even plural: 'Users', since you are already overriding the default?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyways. If you believe that it's better to have /test-users URL even at the cost of making future code archaeology more difficult, then I can live with that.

@@ -78,7 +88,7 @@ describe('User', function() {
assert(err);
assert.equal(err.name, 'ValidationError');
assert.equal(err.statusCode, 422);
assert.equal(err.details.context, 'user');
assert.equal(err.details.context, 'TestUser');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following is better as it should be resistant against future changes:

assert.equal(err.details.context, TestUser.modelName);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Fixed.

@raymondfeng raymondfeng force-pushed the feature/disable-include-access-tokens branch from b6efccc to 12e19e3 Compare April 20, 2015 16:23
@bajtos
Copy link
Member

bajtos commented Apr 20, 2015

LGTM.

raymondfeng added a commit that referenced this pull request Apr 20, 2015
…ss-tokens

Upgrade test fixtures to 2.x project layouts
@raymondfeng raymondfeng merged commit ca004ad into master Apr 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants